package main;

import java.util.*;

/**
 * @Author: gcr
 * @Date: 2022-3-16 15:04
 */
public class TestMesh {
    public static void main(String[] args) {
        String meshStr = "Aldehyde Oxidoreductases|metabolism;Animals;Body Fluids|analysis;Carbon Dioxide|blood;Formates|blood/poisoning;Haplorhini;Humans;Hydrogen-Ion Concentration;Kinetics;Methanol|blood;Methods;Pseudomonas|enzymology";

        Set<String> set = new LinkedHashSet<>();

        String[] split = meshStr.split(";");
        List<String> mesh = new ArrayList<>(Arrays.asList(split));

        getMeSHSet(set, mesh);
        System.out.println(set);

    }

    // 拿主题词：Aqueous Humor|analysis/*drug effects 取出三个。
    public static void getMeSHSet(Set<String> set, List<String> mesh) {
        for (String str : mesh) {
//            str = str.replace("*", "");
            if (str.contains("|")) {
                String name = str.split("\\|")[0];
                String subhead = str.split("\\|")[1];
                if (subhead.contains("/")) {
                    String[] strS = subhead.split("/");
                    for (String s : strS) {
                        set.add(name + " / " + s);
                    }
                } else {
                    set.add(name + " / " + subhead);
                }
//                set.add(name);
            } else {
                set.add(str);
            }
        }
    }

}
